// 表单调试工具
export const formDebugger = {
  // 调试表单数据
  debugFormData: (formName, formInstance, projectData = null) => {
    console.log(`=== ${formName} 表单调试信息 ===`);
    
    // 获取表单当前值
    const formValues = formInstance.getFieldsValue();
    console.log('表单当前值:', formValues);
    
    // 获取表单字段状态
    const fieldsValue = formInstance.getFieldsValue();
    const fieldsError = formInstance.getFieldsError();
    const fieldsTouched = formInstance.isFieldsTouched();
    
    console.log('表单字段值:', fieldsValue);
    console.log('表单字段错误:', fieldsError);
    console.log('表单是否被触摸:', fieldsTouched);
    
    // 如果有项目数据，也显示
    if (projectData) {
      console.log('项目数据:', projectData);
    }
    
    // 检查关键字段
    const requiredFields = ['projectName', 'startDate', 'endDate', 'estimatedCost', 'projectType'];
    const missingFields = requiredFields.filter(field => !formValues[field]);
    
    if (missingFields.length > 0) {
      console.warn('缺少必填字段:', missingFields);
    } else {
      console.log('✅ 所有必填字段都已填写');
    }
    
    console.log('=== 调试信息结束 ===');
    
    return {
      formValues,
      fieldsError,
      fieldsTouched,
      missingFields
    };
  },
  
  // 调试多步骤表单
  debugMultiStepForm: (forms, projectData) => {
    console.log('=== 多步骤表单调试信息 ===');
    
    const results = {};
    
    Object.keys(forms).forEach(stepName => {
      const form = forms[stepName];
      if (form) {
        results[stepName] = formDebugger.debugFormData(stepName, form);
      }
    });
    
    // 显示项目数据
    if (projectData) {
      console.log('项目数据状态:', projectData);
    }
    
    console.log('=== 多步骤表单调试结束 ===');
    
    return results;
  },
  
  // 验证表单数据完整性
  validateFormData: (formData, requiredFields = []) => {
    const missingFields = requiredFields.filter(field => {
      const value = formData[field];
      return !value || (typeof value === 'string' && value.trim() === '');
    });
    
    return {
      isValid: missingFields.length === 0,
      missingFields,
      hasData: Object.keys(formData).length > 0
    };
  }
};

export default formDebugger;
